local a = '111111122222213445555555'
local format = string.format;
local function gen_drscan_tdi(tdi_data)
    local tdi_d = string.reverse(tdi_data);
    local len = 0;
    local hex = '';
    local save_hex = '';
    for w in string.gmatch(tdi_d,"(%x%x)")do
        len = len + 1;
        hex = hex .. w;
        if(len>4)then
            local tcl_str = [[drscan AG10K.tap %d 0x%s -endstate DRSHIFT]]
            tcl_str = format(tcl_str,32,string.reverse(hex));
            print(tcl_str);
            save_hex =  string.reverse(hex) .. save_hex;
            hex = '';
            len = 0;
        end
    end
    --还有剩余数据
    if(len>0)then
        local tcl_str = [[drscan AG10K.tap %d 0x%s -endstate RUN/IDLE]]
        tcl_str = format(tcl_str,8*len,string.reverse(hex));
        print(tcl_str);
    end

    assert(save_hex==tdi_data:sub(#tdi_data-#save_hex+1,#tdi_data),"gen_drscan_tdi error!\n");
end

gen_drscan_tdi(a);
